package com.l024.loanthief.service;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

import com.l024.loanthief.socket.SocketService;
import com.l024.loanthief.utils.Logutils;

import java.io.IOException;

/**
 * 聊天服务
 */
public class ChatService extends Service {

    public ChatService() {
    }


    @Override
    public void onCreate() {
        super.onCreate();
        Logutils.i("服务创建");
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        //
        Logutils.i("服务启动");
        SocketService.getInstance().init();
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public IBinder onBind(Intent intent) {
        Logutils.i("服务绑定");
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Logutils.i("服务销毁");
        try {
            SocketService.getInstance().stopAsync();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
